// @Title  types.go
// @Description  todo
// @Author  xushuai  2023/6/15 5:10 PM

package common

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"net/http"
	"net/url"
)

const HttpRequestKey = "http_request"

type HttpRequest struct {
	Proto            string
	Method           string
	URL              *url.URL
	Header           map[string][]string
	Body             string
	ContentLength    int64
	TransferEncoding []string
	Host             string
	Form             url.Values
	PostForm         url.Values
	RealIp           string
	RemoteAddr       string
	RequestURI       string
	UserAgent        string
	Cookie           []*http.Cookie
	Authorization    string
	Referer          string
	AllMessage       string
}

func GetHttpRequestFromCtx(ctx context.Context) HttpRequest {
	var httpRequest HttpRequest
	httpRequest, ok := ctx.Value(HttpRequestKey).(HttpRequest)
	if !ok {
		logx.WithContext(ctx).Errorf("GetRequestFromCtx  ok: %+v", ok)
	}
	return httpRequest
}
